package com.person.mall.controller;

import com.github.pagehelper.PageInfo;
import com.person.mall.service.Impl.ProductServiceImpl;
import com.person.mall.vo.ProductDetailVo;
import com.person.mall.vo.ResponseVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author 最酷的桃儿wjc
 * * @date 2022/5/18
 */
@RestController
public class ProductController {

    @Autowired
    private ProductServiceImpl productService;

    @GetMapping("/products")
    public ResponseVo<PageInfo> getProductList(
            @RequestParam(required = false) Integer categoryId,
            @RequestParam(required = false,defaultValue = "1") Integer pageNum,
            @RequestParam(required = false,defaultValue = "10") Integer pageSize
    ){
        return productService.productList(categoryId,pageNum,pageSize);
    }

    @GetMapping("/products/{productId}")
    public ResponseVo<ProductDetailVo> productDetailVoResponseVo(@PathVariable Integer productId){
        return productService.productDetail(productId);
    }
}
